import {
  BasicColumn
} from '/@/components/Table';
import {
  FormSchema
} from '/@/components/Table';
import {
  rules
} from '/@/utils/helper/validator';
import {
  render
} from '/@/utils/common/renderUtils';
import {
  JVxeTypes,
  JVxeColumn
} from '/@/components/jeecg/JVxeTable/types'
import {
  log
} from 'console';
//列表数据
export const columns: BasicColumn[] = [{
  title: '单据类型',
  align: "left",
  dataIndex: 'billTypeName',
  width: 120
},
{
  title: '单据编号',
  align: "left",
  dataIndex: 'billCode',
  width: 150
},
{
  title: '类型',
  align: "left",
  dataIndex: 'productPlanType',
  width: 150,
  customRender: ({ text }) => text === 1 ? '前工序工单' : '总装工单'
},
{
  title: '产品编号',
  align: "left",
  dataIndex: 'materialCode',
  width: 150
},
{
  title: '产品名称',
  align: "left",
  dataIndex: 'materialName',
  width: 150
},
{
  title: '图号',
  align: "left",
  dataIndex: 'drawingNo',
  width: 150
},
{
  title: '单位',
  align: "left",
  dataIndex: 'unitName',
  width: 120
},
{
  title: '是否已取消',
  align: "left",
  dataIndex: 'inactiveState',
  width: 100,
  customRender: ({ text }) => text === 1 ? '是' : '否'
},
{
  title: '工单状态',
  align: "left",
  dataIndex: 'billStatus',
  width: 100,
  // options: [{ value: 0, label: '开立' }, { value: 1, label: '核准中' }, { value: 2, label: '已核准' }, { value: 3, label: '开工' }, { value: 4, label: '完工' }],
  customRender: ({ text }) => text === 0 ? '开立' : text === 1 ? '已核准' : text === 2 ? '已开工' : text === 3 ? '已完工' : '' 
},
{
  title: '完工储存地点',
  align: "left",
  dataIndex: 'completeWarehouseName',
  width: 150
},

{
  title: '生产数量',
  align: "right",
  width: 100,
  dataIndex: 'productQuantity'
},
{
  title: '开工数量',
  align: "right",
  dataIndex: 'startQuantity',
  width: 100
},
{
  title: '完工数量',
  align: "right",
  dataIndex: 'completeQuantity',
  width: 100
},
{
  title: '生产部门编码',
  align: "left",
  dataIndex: 'productDepartmentCode',
  width: 150
},
{
  title: '生产部门',
  align: "left",
  dataIndex: 'productDepartmentName',
  width: 150
},

{
  title: '计划开工日期',
  align: "left",
  dataIndex: 'planStartDate',
  width: 160,
  customRender: ({ text }) => !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
},
{
  title: '计划完工日期',
  align: "left",
  dataIndex: 'planCompleteDate',
  customRender: ({ text }) => !text ? "" : (text.length > 10 ? text.substr(0, 10) : text),
  width: 160
},
{
  title: '实际开工时间',
  align: "left",
  dataIndex: 'businessStartDate',
  customRender: ({
    text
  }) => {
    return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
  },
  width: 120
},
{
  title: '实际完工时间',
  align: "left",
  dataIndex: 'businessEndDate',
  customRender: ({
    text
  }) => {
    return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
  },
  width: 120
},
{
  title: '入库数量',
  align: "right",
  dataIndex: 'storageQuantity',
  width: 100
},
{
  title: '返工数量',
  align: "right",
  dataIndex: 'returnQuantity',
  width: 100
},
{
  title: '返工补单数量',
  align: "right",
  dataIndex: 'returnOrderQuantity',
  width: 100
},
{
  title: '报废补单数量',
  align: "right",
  dataIndex: 'scrapOrderQuantity',
  width: 100
},
{
  title: 'MRP数量',
  align: "right",
  dataIndex: 'mrpQuantity',
  width: 100
},
{
  title: '备注',
  align: "left",
  dataIndex: 'remark',
  width: 100
},
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    field: 'materialName',
    label: '产品名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'materialCode',
    label: '产品编号',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'billCode',
    label: '单据编号',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'billStatus',
    label: '工单状态',
    component: 'Select',
    colProps: { span: 8 },
    componentProps: {
      options: [{ value: 0, label: '开立' }, { value: 1, label: '核准中' }, { value: 2, label: '已核准' }, { value: 3, label: '开工' }, { value: 4, label: '完工' }]
    }
  },
  // billStatus
];
//表单数据  基础信息
export const formSchema: FormSchema[] = [{
  label: '单据类型Id',
  field: 'billTypeId',
  component: 'Input',
  show: false
}, 
// {
//   label: '单据类型',
//   field: 'billTypeName',
//   component: 'Input',
//   slot: 'billTypeSlot',
//   dynamicRules: () => {
//     return [{
//       required: true,
//       message: '请选择单据类型!'
//     },];
//   },
// },
{
  label: '工单类型',
  field: 'productPlanType',
  component: 'Select',
  componentProps: {
    options: [{
      value: 0,
      label: '总装'
    }, {
      value: 1,
      label: '前工序'
    }],
    stringToNumber: true,
  },
},
{
  label: '单据编号',
  field: 'billCode',
  component: 'Input',
  dynamicDisabled: () => true,
  componentProps: {
    placeholder: '根据编码规则自动生成',
  }
},
{
  label: '产品编号',
  field: 'materialCode',
  slot: 'materialSlot',
  dynamicRules: () => {
    return [{
      required: true,
      message: '请选择产品编号!'
    },];
  },
  component: 'Input',
},
{
  label: '产品Id',
  field: 'materialId',
  component: 'Input',
  dynamicDisabled: () => {
    return true;
  },
  show: false
},
{
  label: '产品名称',
  field: 'materialName',
  component: 'Input',
  dynamicDisabled: () => {
    return true;
  }
},
{
  label: '单位',
  field: 'unitName',
  component: 'Input',
  dynamicDisabled: () => {
    return true;
  },
  dynamicRules: () => {
    return [{
      required: true,
      message: '请选择单位!'
    },];
  },
},
{
  label: '完工储存地点Id',
  field: 'completeWarehouseId',
  component: 'Input',
  ifShow: false
},
{
  label: '完工储存地点',
  field: 'completeWarehouseName',
  component: 'Input',
  slot: 'completeWarehouseSlot',
  dynamicRules: () => {
    return [{
      required: true,
      message: '请选择完工储存地点!'
    },];
  },
},
{
  label: '生产部门编码',
  field: 'productDepartmentCode',
  component: 'Input',
  ifShow: false
},
{
  label: '产线',
  field: 'productLineName',
  component: 'Input'
},
{
  label: '班组',
  field: 'teamGroupName',
  component: 'Input'
},
{
  label: '工段',
  field: 'workSectionName',
  component: 'Input'
},
{
  label: '生产部门',
  field: 'productDepartmentId',
  component: 'JSelectDept',
  componentProps: ({ }) => {
    return {
      multiple: false,
      showButton: false,
      checkable: false,
      isCode: true,
      rowKey: 'id',
      labelKey: 'departName'
    }
  },
  dynamicRules: () => {
    return [{
      required: true,
      message: '请选择生产部门!'
    },];
  },
},
{
  label: 'BOM生产目的',
  field: 'bomProductPurpose',
  component: 'Select',
  componentProps: {
    options: [{
      value: 0,
      label: '主制件'
    }, {
      value: 1,
      label: '委外'
    }],
    stringToNumber: true,
  },
  dynamicRules: () => {
    return [{
      required: true,
      message: '请选择BOM生产目的!'
    },];
  },
},
{
  label: 'BOM类型',
  field: 'bomType',
  component: 'Select',
  componentProps: {
    options: [{
      value: 0,
      label: '主制件'
    }, {
      value: 1,
      label: '委外'
    }],
    stringToNumber: true,
  },
  dynamicRules: () => {
    return [{
      required: true,
      message: '请选择BOM生产目的!'
    },];
  },
},
{
  label: '生产数量',
  field: 'productQuantity',
  component: 'InputNumber',
  dynamicRules: () => {
    return [{
      required: true,
      message: '请输入生产数量!'
    },];
  },
},
{
  label: '订单编号',
  field: 'orderBillCode',
  component: 'Input',
},
{
  label: '订单行号',
  field: 'orderRowNum',
  component: 'Input',
},
{
  label: 'MRP数量',
  field: 'mrpQuantity',
  component: 'InputNumber',
  dynamicRules: ({ }) => {
    return [{
      required: true,
      message: '请输入MRP数量!'
    },];
  },
},
{
  label: '计划开工日期',
  field: 'planStartDate',
  component: 'DatePicker',
  dynamicRules: () => {
    return [{
      required: true,
      message: '请选择计划开工日!'
    },];
  },
},
{
  label: '计划完工日期',
  field: 'planCompleteDate',
  component: 'DatePicker', dynamicRules: () => {
    return [{
      required: true,
      message: '请选择计划完工日!'
    },];
  },
},
{
  label: '实际开工日期',
  field: 'businessStartDate',
  component: 'DatePicker',
},
{
  label: '实际完工日期',
  field: 'businessEndDate',
  component: 'DatePicker',
},
{
  label: '备注',
  field: 'remark',
  component: 'Input',
},
{
  label: '工单状态',
  field: 'billStatus',
  component: 'Select',
  slot: 'billStatusSlot',
  // dynamicDisabled: (text) => {
  //   return text.values.billStatus !== 0 && text.values.billStatus !== 1
  //   // return ;
  // },
  componentProps: {
    options: [{ value: 0, label: '开立' }, { value: 1, label: '已核准' }, { value: 2, label: '开工' }, { value: 3, label: '完工' }],
    stringToNumber: true,
  },
},
// {
//   label: '完工储存地点',
//   field: 'completeWarehouseName',
//   component: 'Input',
//   slot: 'completeWarehouseSlot',
//   dynamicRules: () => {
//     return [{
//       required: true,
//       message: '请选择完工储存地点!'
//     },];
//   },
// },
{
  label: '第三方编码',
  field: 'thirdPartyCode',
  component: 'Input',
  ifShow: false
},
// TODO 主键隐藏字段，目前写死为ID
{
  label: '',
  field: 'id',
  component: 'Input',
  show: false
},
];
// 表单数据  存储信息
export const formStoreSchema: FormSchema[] = [
  {
    label: '存储地点Id',
    field: 'storageWarehouseId',
    component: 'Input',
    ifShow: false
  },
  {
    label: '存储地点',
    field: 'storageWarehouseName',
    component: 'Input',
    slot: 'storageWarehouseSlot',
    dynamicRules: () => {
      return [{
        required: true,
        message: '请选择储存地点!'
      },];
    },
  },
  {
    label: '开工数量',
    field: 'startQuantity',
    component: 'InputNumber'
  },
  {
    label: '返工数量',
    field: 'returnQuantity',
    component: 'InputNumber'
  },
  {
    label: '完工数量',
    field: 'completeQuantity',
    component: 'InputNumber'
  },
  {
    label: '入库数量',
    field: 'storageQuantity',
    component: 'InputNumber'
  },
  {
    label: '报废数量',
    field: 'scrapQuantity',
    component: 'InputNumber',
  },
  {
    label: '返工补单数量',
    field: 'returnOrderQuantity',
    component: 'InputNumber',
  },
  {
    label: '报废补单数量',
    field: 'scrapOrderQuantity',
    component: 'InputNumber',
  },
  {
    label: '项目',
    field: 'projectName',
    component: 'Input',
  },
  {
    label: '任务',
    field: 'taskName',
    component: 'Input',
  },
  {
    label: '番号',
    field: 'designation',
    component: 'Input',
  },
  {
    label: '需求分类',
    field: 'demandCategory',
    component: 'Input',
  },
  {
    label: '生产批号',
    field: 'productBatchNumber',
    component: 'Input',
  },
  // {
  //   label: '单据状态',
  //   field: 'billStatus',
  //   component: 'InputNumber',
  // },
  {
    label: '计算成本',
    field: 'calculateCost',
    component: 'Select',
    componentProps: {
      options: [{
        value: 0,
        label: '否'
      }, {
        value: 1,
        label: '是'
      }],
      stringToNumber: true,
    }
  },
  {
    label: '成本要素',
    field: 'costElementName',
    component: 'Input',
  },
  {
    label: '成本单位',
    field: 'costUnitName',
    component: 'Input',
  },
  {
    label: '供应方式',
    field: 'supplyMethod',
    component: 'Select',
    componentProps: {
      options: [{
        value: 0,
        label: '生产组织'
      }, {
        value: 1,
        label: '指定组织'
      }, {
        value: 2,
        label: '委外商'
      }],
      stringToNumber: true,
    }
  },
  {
    label: '委托料品来源',
    field: 'delegateMaterialSources',
    component: 'Select',
    componentProps: {
      options: [{
        value: 0,
        label: '受托方领料'
      }, {
        value: 1,
        label: '受托方供料'
      }],
      stringToNumber: true,
    }
  },
  {
    label: '发料方式',
    field: 'sendMaterialMethod',
    component: 'Select',
    componentProps: {
      options: [{
        value: 0,
        label: '推式'
      }, {
        value: 1,
        label: '工序倒冲'
      }, {
        value: 2,
        label: '开工倒冲'
      }, {
        value: 3,
        label: '完工倒冲'
      }, {
        value: 4,
        label: '不发料'
      }],
      stringToNumber: true,
    }
  },
  {
    label: '倒冲时机',
    field: 'backflushTiming',
    component: 'Select',
    componentProps: {
      options: [{
        value: 0,
        label: '即时'
      }],
      stringToNumber: true,
    }
  },
  {
    label: '数量类型',
    field: 'quantityType',
    component: 'Select',
    componentProps: {
      options: [{
        value: 0,
        label: '变动'
      }],
      stringToNumber: true,
    }
  }]
//子表单数据
//子表表格配置
export const busProductionPlanInformationColumns: JVxeColumn[] = [
  {
    title: '行号',
    key: 'rowNum',
    type: JVxeTypes.inputNumber,
    width: "80px",
    validateRules: [{
      required: true, message: '${title}不能为空'
    }]
  },
  {
    title: '生产工单ID',
    key: 'productOrderId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '产品ID',
    key: 'materialId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '料号',
    key: 'materialCode',
    type: JVxeTypes.input,
    slotName: 'action',
    width: "200px",
    placeholder: '请选择${title}'
  },
  {
    title: '品名',
    key: 'materialName',
    type: JVxeTypes.normal,
    width: "200px",
  },
  {
    title: '规格',
    key: 'spec',
    type: JVxeTypes.normal,
    width: "200px",
  },
  {
    title: '图号',
    key: 'drawingNo',
    type: JVxeTypes.normal,
    width: "200px",
  },
  {
    title: '产线',
    key: 'productLineName',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    width: "200px",
  },
  {
    title: '班组',
    key: 'teamGroupName',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    width: "200px",
  },
  {
    title: '工段',
    key: 'workSetionName',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    width: "200px",
  },
  {
    title: 'BOM需求',
    key: 'bomDemandQuantity',
    type: JVxeTypes.inputNumber,
    width: "130px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '需求数量',
    key: 'actualDemandQuantity',
    type: JVxeTypes.inputNumber,
    width: "120px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '需求日期',
    key: 'actualDemandDate',
    type: JVxeTypes.date,
    width: "150px",
    placeholder: '请选择${title}',
  },
  {
    title: '发料仓库Id',
    key: 'issueWarehouseId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '发料仓库',
    key: 'issueWarehouseCode',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
  },
  {
    title: '发料仓库',
    key: 'issueWarehouseName',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
  },
  {
    title: '发料数量',
    key: 'issuedQuantity',
    type: JVxeTypes.inputNumber,
    width: "120px",
    placeholder: '请输入${title}',
  },
  {
    title: '退料数量',
    key: 'returnQuantity',
    type: JVxeTypes.inputNumber,
    width: "100px",
    placeholder: '请输入${title}',
  },
  {
    title: '单位ID',
    key: 'unitId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '单位',
    key: 'unitName',
    width: "100px",
    type: JVxeTypes.normal
  },
  {
    title: '固定损耗',
    key: 'fixedLoss',
    width: "100px",
    type: JVxeTypes.normal
  },
  {
    title: '变动损耗率',
    key: 'variableLoss',
    width: "120px",
    type: JVxeTypes.normal
  },
  // {
  //   title: '库存可用量',
  //   key: 'availableInventoryQuantity',
  //   type: JVxeTypes.inputNumber,
  //   width: "120px",
  //   placeholder: '请输入${title}',
  // },
  // {
  //   title: '可用量',
  //   key: 'availableQuantity',
  //   type: JVxeTypes.inputNumber,
  //   width: "100px",
  //   placeholder: '请输入${title}',
  // },
  // {
  //   title: '预留量',
  //   key: 'reservedQuantity',
  //   type: JVxeTypes.inputNumber,
  //   width: "100px",
  //   placeholder: '请输入${title}',
  // },
]
export const busProductionPlanProcessTableColumns: JVxeColumn[] = [
  // {
  //   title: '行号',
  //   key: 'rowNum',
  //   type: JVxeTypes.inputNumber,
  //   width: "80px",
  //   validateRules: [{
  //     required: true, message: '${title}不能为空'
  //   }]
  // },
  // {
  //   title: '生产工单ID',
  //   key: 'productOrderId',
  //   type: JVxeTypes.hidden,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  {
    title: '工序号',
    key: 'processNumber',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '工序ID',
    key: 'processId',
    type: JVxeTypes.hidden,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '工序名称',
    key: 'processName',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '工种',
    key: 'workType',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '图号',
    key: 'drawingNumber',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '是否委外工序',
    key: 'whetherOutsourceProcess',
    type: JVxeTypes.select,
    options: [{
      value: 0,
      label: '否'
    }, {
      value: 1,
      label: '是'
    }],
    placeholder: '请选择${title}',
    defaultValue: '',
  },
  // {
  //   title: '备注',
  //   key: 'remark',
  //   type: JVxeTypes.input,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  // {
  //   title: '第三方编码',
  //   key: 'thirdPartyCode',
  //   type: JVxeTypes.input,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  // {
  //   title: '组织ID',
  //   key: 'organizationId',
  //   type: JVxeTypes.hidden,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  // {
  //   title: '租户ID',
  //   key: 'tenantId',
  //   type: JVxeTypes.hidden,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
]
export const BusCancelWorkOrderData: FormSchema[] = [
  {
    label: '单据编号',
    field: 'billCode',
    component: 'Input',
    colProps: {
      span: 12
    },
    dynamicDisabled: true
  },
  {
    label: '产品编号',
    field: 'materialCode',
    component: 'Input',
    colProps: {
      span: 12
    },
    dynamicDisabled: true
  },
  {
    label: '产品名称',
    field: 'materialName',
    component: 'Input',
    colProps: {
      span: 24
    },
    dynamicDisabled: true
  },
  {
    label: '取消数量',
    field: 'cancellationQuantity',
    component: 'InputNumber',
    colProps: {
      span: 24
    },
    dynamicRules: () => {
      return [{
        required: true,
        message: '请输入取消数量'
      },];
    },
    // dynamicDisabled: true
  }
]
// 转单-表单数据
export const transferOrderData: FormSchema[] = [
  {
    label: '单据编号',
    field: 'billCode',
    component: 'Input',
    colProps: {
      span: 12
    },
    dynamicDisabled: true
  }, {
    label: '产品编号',
    field: 'materialCode',
    component: 'Input',
    colProps: {
      span: 12,
    },
    dynamicDisabled: true
  },
  {
    label: '产品名称',
    field: 'materialName',
    component: 'Input',
    colProps: {
      span: 24
    },
    dynamicDisabled: true
  },
  {
    label: '生产部门',
    field: 'productDepartmentId',
    component: 'JSelectDept',
    colProps: {
      span: 12,
    },
    componentProps: ({ }) => {
      return {
        multiple: false,
        showButton: false,
        checkable: false,
        labelKey: 'departName'
      }
    },
  },
  {
    label: '开工日期',
    field: 'planStartDate',
    component: 'DatePicker',
    colProps: {
      span: 12,
    },
    componentProps: {
      // showTime: true,
      valueFormat: 'YYYY-MM-DD',
      getPopupContainer: () => document.body,
    },
  },
  // 必须要写  否则formActionType.getFieldsValue()拿不到值
  {
    label: '生产数量',
    field: 'productQuantity',
    component: 'Input',
    ifShow: false
  },
  // 必须要写  否则formActionType.getFieldsValue()拿不到值
  {
    label: '完工数量',
    field: 'completeQuantity',
    component: 'Input',
    ifShow: false
  },
  {
    label: '转单数量',
    field: 'transferQuantity',
    component: 'InputNumber',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      //通过formActionType 获取form的methods，
      let formData = formActionType.getFieldsValue();
      // 转单数量默认为生产数量-完工数量
      formModel.transferQuantity = formData.productQuantity - formData.completeQuantity;
    },
    colProps: {
      span: 12,
    },
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
